package com.work.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.work.dao.GoodsDao;
import com.work.pojo.Goods;
import com.work.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class,readOnly = true,propagation = Propagation.SUPPORTS)
public class GoodsServiceImpl implements GoodsService {
    @Autowired
   private GoodsDao goodsDao;
    @Override
    public void addGoods(Goods goods) {
        goodsDao.addGoods(goods);
    }

    @Override
    public List<Goods> getGoodsList() {
        List<Goods> goodsList = goodsDao.getGoodsList();

        return goodsList;
    }

    @Override
    public PageInfo getGoodsListByTypeId(int id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List goodsListByTypeId= goodsDao.getGoodsListByTypeId(id);
        PageInfo<Goods> goodsPageInfo = new PageInfo<Goods>( goodsListByTypeId );

        return goodsPageInfo;
    }

    @Override
    public Goods getGoods(Integer id) {
       Goods goods= goodsDao.getGoods(id);
       return goods;
    }
}
